package com.chernyak.DataAdapter;

import java_cup.runtime.*;

%%

%public
%final
%class DataAdapterLexer
%yylexthrow CompilerException
%unicode
%line
%column
%cup

%{
    /* To create a new java_cup.runtime.Symbol with information about
       the current token, the token will have no value in this
       case. */
    private Symbol symbol(int type) {
        return new Symbol(type, yyline, yycolumn);
    }
    
    /* Also creates a new java_cup.runtime.Symbol with information
       about the current token, but this object has a value. */
    private Symbol symbol(int type, Object value) {
        return new Symbol(type, yyline, yycolumn, value);
    }
%}

/*
  Macro Declarations  
*/
   
LineTerminator 	= \r|\n|\r\n
InputCharacter 	= [^\r\n]
WhiteSpace     	= {LineTerminator} | [ \t\f]

TraditionalComment   = "/*" [^*] ~"*/" | "/*" "*"+ "/"
EndOfLineComment     = "//" {InputCharacter}* {LineTerminator}
CommentContent       = ( [^*] | \*+ [^/*] )*

Comment = {TraditionalComment} | {EndOfLineComment}   
   
Ident 		= [A-Za-z_][A-Za-z_0-9]+

%%
<YYINITIAL> {

 ";"		{ return symbol(sym.DAFIELDSEP); }
 "[]"		{ return symbol(sym.DAARR); }
 "{"		{ return symbol(sym.DAOPEN); }
 "}"		{ return symbol(sym.DACLOSE); }
 "."		{ return symbol(sym.NAMESEP); }

 "byte" 	{ return symbol(sym.BYTE); }
 "short" 	{ return symbol(sym.SHORT); }
 "int" 		{ return symbol(sym.INT); }
 "long" 	{ return symbol(sym.LONG); }
 "float" 	{ return symbol(sym.FLOAT); }
 "double" 	{ return symbol(sym.DOUBLE); }
 "boolean" 	{ return symbol(sym.BOOLEAN); }
 "char" 	{ return symbol(sym.CHAR); }
 "String"	{ return symbol(sym.STRING); }

 "compare"	{ return symbol(sym.COMPARE); }

 {Ident}	{ return symbol(sym.NAME, new String(yytext())); }

 {WhiteSpace}	{ /* no op */ }
 {Comment}	{ /* no op */ }

}

[^] 		{ throw new Error("Illegal token <"+yytext()+">"); }
